﻿
function goBack() {
    location.href = "/City/CityList";
}
function SubData() {
    var postData = {
        CityID: $("#hid").val(),
        CityName: $("#cityname").val().trim(),
        ProvinceID: $("#proList").val(),
        IsActive: $("#PIsActive").val(),
        CreateTime: $("#hidCreateTime").val(),
        CreateUserID: $('#hidCreateUserID').val(),
        Remark: HtmlUtil.htmlEncodeByRegExp(CKEDITOR.instances.desTextarea.getData())
    };

    //使用异步进行修改数据的信息
    $.post("/City/Updatecityinfo", postData, function (date) {
        if (date == "suc") {
            //关闭层，刷新表单
            goBack();
        }
        else if (date == "repeat") {
            $.alert({
                title: '系统提示',
                content: '重复数据无法保存！',
                confirm: function () {
                }
            });
        }
        else if (date == "nouser") {
            location.href = '/Login/Index';
        }
        else {
            $.alert({
                title: '系统提示',
                content: '操作失败',
                confirm: function () {
                }
            });
        }
    });
}


$(document).ready(function () {
    $("#rightResources").addClass("active");
    CKEDITOR.replace('desTextarea', {
        toolbar: 'Basic'
        //uiColor: '#9AB8F3'//界面颜色
    });
    CKEDITOR.instances.desTextarea.setData(HtmlUtil.htmlDecodeByRegExp($('#hidCom').val()));
    //var toolid = $("#hid").val();
    //if (toolid != undefined) {
    //    $.ajax({
    //        data: { id: toolid },
    //        type: "POST",
    //        url: "/City/GetCityInfobyID",
    //        cache: false,
    //        datatype: "json",
    //        success: function (data) {
    //            $("#cityname").val(data.CityName);
    //            $("#hid").val(data.CityID);
    //            $("#hidProvinceid").val(data.ProvinceID);
    //            CKEDITOR.instances.desTextarea.setData(HtmlUtil.htmlDecodeByRegExp(data.Comments));
    //        }
    //    });
    //}
    $('#CityUpdateForm')
  .bootstrapValidator({
      message: 'This value is not valid',
      feedbackIcons: {
          valid: 'glyphicon glyphicon-ok',
          invalid: 'glyphicon glyphicon-remove',
          validating: 'glyphicon glyphicon-refresh'
      },
      fields: {
          cityname: {
              message: 'The City Name is not valid',
              validators: {
                  notEmpty: {
                      message: 'The City Name is required and can\'t be empty'
                  }
              }
          },
          proList: {
              message: 'The Province is not valid',
              validators: {
                  notEmpty: {
                      message: 'The Province is required and can\'t be empty'
                  }
              }
          }
      }
  })
  .on('success.form.bv', function (e) {
      e.preventDefault();
      SubData();
  });
});
